﻿using System;
using System.IO;

namespace DatabaseGroup.SSIS.SourceAdapters
{
    /// <summary>
    /// Checks the state of an argument and throws an exception if
    /// the argument does not meet the expected state
    /// </summary>
    public class ArgumentVerifier
    {
        /// <summary>
        /// Checks to see if the argument is not null and 
        /// throws ArgumentNullException if it is
        /// </summary>
        /// <param name="argument">The argument to check</param>
        /// <param name="argumentName">The name of the argument</param>
        public static void CheckObjectArgument(object argument, string argumentName)
        {
            if (argument == null)
                throw new ArgumentNullException(argumentName);
        }

        /// <summary>
        /// Checks to see if the string argument is not null and not empty,
        /// if it is either it will throw an ArgumentNullException
        /// </summary>
        /// <param name="stringArgument">The string argument to check</param>
        /// <param name="argumentName">The name of the argument</param>
        public static void CheckStringArgument(string stringArgument, string argumentName)
        {
            if (string.IsNullOrEmpty(stringArgument))
                throw new ArgumentNullException(argumentName);
        }

        /// <summary>
        /// Checks to see if the file name is valid and exists,
        /// otherwise throws an ArgumentException
        /// </summary>
        /// <param name="fileName">The filename to check</param>
        public static void CheckFileNameArgument(string fileName)
        {
            CheckStringArgument(fileName, "fileName");

            if (!File.Exists(fileName))
                throw new ArgumentException(MessageStrings.FileDoesNotExist(fileName));
        }
    }
}
